import subprocess

output = subprocess.check_output(
    "netstat -tlnp 2>/dev/null | grep 1234 | awk '{print $7}'", shell=True)
if output:
    pid = output[:output.find('/')]
    subprocess.call(["kill", "-9", pid])
    print "service on port 1234 has stopped ..."
else:
    print "service on port 1234 is not running"
